package sim.tests.games.snake;

import com.badlogic.gdx.math.Vector2;

import sim.Image;
import sim.Sprite;
import sim.tests.games.snake.SnakeGame.CompassDirection;

public class SnakePart extends Sprite
{
	Vector2 direction = new Vector2(0, 1);

	public SnakePart(Vector2 pos)
	{
		super(new Image("crate.png"), pos);
		image.setSize(1, 1);
		
	}
	
	public SnakePart(float x, float y)
	{
		this(new Vector2(x, y));
	}
	
	public void move(SnakeGame.CompassDirection cd)
	{
		if (cd.equals(CompassDirection.North))
		{
			image.setRotation(0);
			//pos.y++;
			direction.x = 0;
			direction.y = 1;
		}

		if (cd.equals(CompassDirection.East))
		{
			direction.x = 1;
			direction.y = 0;
			image.setRotation(90);
			//pos.x++;
		}

		if (cd.equals(CompassDirection.South))
		{
			direction.x = 0;
			direction.y = -1;
			image.setRotation(180);
			//pos.y--;
		}

		if (cd.equals(CompassDirection.West))
		{
			direction.x = -1;
			direction.y = 0;
			image.setRotation(-90);
			//pos.x--;
		} 
	}
	
	@Override
	public void update(float timeStep)
	{
		
			
			SnakeGame.grid[(int) pos.y][(int) pos.x] = null;
			pos.add(direction);
			SnakeGame.grid[(int) pos.y][(int) pos.x] = this;
			
		

		super.update(timeStep);
	}
	
	

}
